package com.info.controller;

import com.info.bll.UserBLL;
import com.info.dal.UserDAL;
import com.info.model.UserInfo;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "deleteUserByIdServlet", value = "/admin/deleteUserByIdServlet")
public class deleteUserByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取删除用户的user_id
        Integer user_id = Integer.parseInt(request.getParameter("id"));
        System.out.println("user_id:"+user_id);
        //装载传参对象
        UserInfo user = new UserInfo();
        user.setUser_id(user_id);
        //调用后端封装接口方法执行删除操作
        UserBLL userBLL = new UserBLL();
        if(userBLL.deleteUserById(user)){
            //删除成功
            response.sendRedirect("success.jsp");
        }else {
            //删除失败
            response.sendRedirect("error.jsp");
        }
    }
}
